<!DOCTYPE html>
<?php
include_once("inc/constants.inc.php");
include_once("inc/connection.php");
session_start();

if(!isset($_SESSION['login']) || empty($_SESSION['login']) || !isset($_SESSION['email']) || empty($_SESSION['email']) || !isset($_SESSION['user_role']))
	{
		header("Location: login.php?error=invalid-access");
		exit(0);
	}
elseif($_SESSION['user_role']==2)
	{
		header("Location: test.php?error=invalid-access");
		exit(0);
	}
?>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>Smartek online test | View List of Question</title>
		<link rel="SHORTCUT ICON" href="img/disp/favicon.png" />	
		<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>
	</head>
	<body>
		<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
		<script src="js/bootstrap.js"></script>
		
		<div class="container">
			<a href="index.php"><img src="img/disp/logo.png" alt=""></a>
		</div>
		
		<div class="container">
			<a href="logout.php" class="pull-right">Logout</a>
		</div>
		
		
		<div class="container">
			<hr class="featurette-divider">
		</div>

		<div class="container">
			<div class="row">
				<div class="span12" > <!--pagination-centered-->


				<form action="dashboard.php">
					<input type="submit" name="backToDashboard" class="btn" value="Back To Dashboard"> <br/>
				</form>
<?php
		//$_SESSION['test_type'] = $_POST['test_type'];	
		

			if(isset($_GET['typeId']))
			{
				$_SESSION['typeId'] = $_GET['typeId'];
				$typeId = $_SESSION['typeId'];
				
				$result = mysql_query("SELECT * FROM question_type WHERE QTypeID='$typeId'");	
				while($row = mysql_fetch_array($result))
					{
						$userName = $row['QType'];
					}
				if(isset($_GET['isEmpty']))
					{
						echo "<font color='red'>All Fields are mendatory</font><br/>";
					}
				if(isset($_GET['isEmptyCheck']))
					{
						echo "<font color='red'>Select the correct answer</font><br/>";
					}
				if(isset($_GET['isUpdated']) && $_GET['isUpdated']=="yes")
					{
						echo "<font color='blue'>Updated Successfully</font><br/><br/>";
					}
				if(isset($_GET['isDeleted']) && $_GET['isDeleted']=="yes")
					{
						echo "<font color='blue'>Deleted Successfully</font><br/><br/>";
					}	
			
				if(isset($_GET['showField']) && $_GET['showField']=="yes")
					{
?>
			<br/><br/>
		<form action="process/add-question.php" method="POST">
			<textarea placeholder="No need to write Question Number" style="resize:vertical; width:920px" 
			name="questionTextArea" 			
			><?php 			
			if(isset($_GET['isEmpty']))
				{
					if(!empty($_GET['question']))
						{
						echo $_GET['question'];			
						}			
				} 	
				
	/*
	*
	*	$_GET['hiddenQuestionId']  is question no. -----from edit / delete
	*
	*/
				
				
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysql_query("SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysql_fetch_array($result))
					{	
						echo $row['question'];
					}
			}
			?></textarea> 	<br/><br/>			
			
			<input type="radio" name="optionRadio" value="a">
			A. <input placeholder="Select radio button for correct option" type="text" style="width:880px" name="optionOne" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
			{
				if(!empty($_GET['one']))
				{
				echo $_GET['one'];			
				}			
			}
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysql_query("SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysql_fetch_array($result))
					{	
						echo $row['optionOne'];
					}
			}
			?>">
			<br/>
			<input type="radio" name="optionRadio" value="b">
			B. <input placeholder="Select radio button for correct option" type="text" style="width:880px" name="optionTwo" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['two']))
				{
				echo $_GET['two'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysql_query("SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysql_fetch_array($result))
					{	
						echo $row['optionTwo'];
					}
			}
			?>">
			
			<br/>
			
			<input type="radio" name="optionRadio" value="c">
			C. <input placeholder="Select radio button for correct option" type="text" style="width:880px" name="optionThree" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['three']))
				{
				echo $_GET['three'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysql_query("SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysql_fetch_array($result))
					{	
						echo $row['optionThree'];
					}
			}
			?>">			
			<br/>
			<input type="radio" name="optionRadio" value="d">
			D. <input placeholder="Select radio button for correct option" type="text" style="width:880px" name="optionFour" 
			value="<?php 			
			if(isset($_GET['isEmpty']))
				{
				if(!empty($_GET['four']))
				{
				echo $_GET['four'];			
				}			
			} 
			elseif(isset($_GET['hiddenQuestionId']))
			{
				$questionId = $_GET['hiddenQuestionId'];
				$result = mysql_query("SELECT * FROM question_table where questionNumber='$questionId'");		
				while($row = mysql_fetch_array($result))
					{	
						echo $row['optionFour'];
					}
			}
			?>">				
			<br/>
			<p align="right">
			<input type="hidden" name="hiddenQuestionId" value="<?php
				if(isset($_GET['hiddenQuestionId']))
					{
						echo $_GET['hiddenQuestionId'];
					}			
			?>">
			
			
			<br/>
			<input type="hidden" name="fromViewList" value="viewList">
<?php

					echo "<input type='submit' name='questionUpdateButton' class='btn' value='Update'>";
				

?>

				<input type="reset" name="reset" class="btn" value="Reset">
				
			</p>
		</form>
<?php			
			
					}	
			/*
			*
			*	To Display the added questions
			*
			*/
			
			echo "<br/><br/><form action='' method='GET'>";
			$result = mysql_query("SELECT * FROM question_table WHERE typeId='$typeId'");		
			$i = 1;
			while($row = mysql_fetch_array($result))
				{	
					echo $i++ . ".";
					echo "<b>" . $row['question'] . "</b><br/>" ;
					echo "a. " . $row['optionOne'] . "<br/>" ;
					echo "b. " . $row['optionTwo'] . "<br/>" ;
					echo "c. " . $row['optionThree'] . "<br/>" ;
					echo "d. " . $row['optionFour'] . "<br/>" ;
					echo "<b>Correct Answer : </b>" . $row['correctAnswer'] . "<br/><br/>" ;
					echo "<input type='hidden' name='hiddenQuestionId' value='$row[questionNumber]'>";
					echo "<a href='question-list.php?hiddenQuestionId=$row[questionNumber]&typeId=$typeId&showField=yes'>Edit</a>&nbsp;&nbsp;&nbsp;
						<a href='process/add-question.php?&delete=yes&deleteQuestionId=$row[questionNumber]&selectType=$typeId&fromList=yes'>Delete</a>" . "<br/><br/>" ;
				}
				
	
				
				echo "</form>";
			}
		else
			{
				
			}
			
			
			//exit(0);
			



?>
	
				<form action="dashboard.php">
					<input type="submit" name="backToDashboard" class="btn" value="Back To Dashboard"> <br/>
				</form>

			</div>
		</div>
	</div>

		
		<div class="container marketing">
      <!-- FOOTER -->
		<div class="container">
			<hr class="featurette-divider">
		</div>
      <footer>
        <p>&copy; 2014 SCS &middot; </p>
      </footer>

    </div><!-- /.container -->
	</body>
</html>